package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
@Api(tags = "套餐相关接口")
public class SetmealController {


    @Autowired
    private SetmealService setmealService;


    @GetMapping("dish/{id}")
    @ApiOperation("根据套餐id查询套餐包含的菜品")
    public Result<List<DishItemVO>> getById(@PathVariable Long id){
        log.info("根据套餐id查询套餐包含的菜品 : {}",id);
        List<DishItemVO> dishItemVOs = setmealService.getByIdWithDish(id);
        return Result.success(dishItemVOs);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询起售的套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> getByCategoryId(@RequestParam Long categoryId){
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        log.info("根据分类id查询起售的套餐 : {}",categoryId);
        List<Setmeal> setmeals = setmealService.getByCategoryId(setmeal);
        return Result.success(setmeals);
    }


}
